using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;
using System.Data;
using DataAccess;

namespace Business
{
    public class ApplicationsBusiness
    {
        public DataTable GetApplications()
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Applications";
            dt = DA.GetDataTable(sql);
            return dt;
        }

        public int AddApplication(ApplicationsEntity applications)
        {
            int i = 0;
            string sql = "INSERT into [dbo].[Applications] VALUES (@ApplicantID, @JobPostingID, @ResumeID, @ApplicationStatus)";
            string[] paras = { "@ApplicantID", "@JobPostingID", "@ResumeID", "@ApplicationStatus" };
            object[] values = { applications.ApplicantID, applications.JobPostingID, applications.ResumeID, applications.ApplicationStatus };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public int UpdateApplication(ApplicationsEntity applications)
        {
            int i = 0;
            string sql = "UPDATE [dbo].[Applications] SET ApplicantID = @ApplicantID, JobPostingID = @JobPostingID, ResumeID = @ResumeID, ApplicationStatus = @ApplicationStatus WHERE ApplicationID = @ApplicationID";
            string[] paras = { "@ApplicantID", "@JobPostingID", "@ResumeID", "@ApplicationStatus", "@ApplicationID" };
            object[] values = { applications.ApplicantID, applications.JobPostingID, applications.ResumeID, applications.ApplicationStatus, applications.ApplicationID };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public int DeleteApplication(int ApplicationID)
        {
            int i = 0;
            string sql = "DELETE FROM [dbo].[Applications] WHERE ApplicationID = @ApplicationID";
            string[] paras = { "@ApplicationID" };
            object[] values = { ApplicationID };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public DataTable GetApplication(int ApplicationID)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Applications WHERE ApplicationID = @ApplicationID";
            string[] paras = { "@ApplicationID" };
            object[] values = { ApplicationID };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }

        public DataTable GetApplication(int ApplicantID)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Applications WHERE ApplicantID = @ApplicantID";
            string[] paras = { "@ApplicantID" };
            object[] values = { ApplicantID };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }
    }
}
